package edu.midir.demo.pojo.enumeration;

/**
 *
 * Author wuky
 * @date 2017/5/5 9:43
 * @date 2018/2/8 copy by yangzhi ahhahha  code 也是string ，因为之前是string，
 * version V1.0.0
 */
public enum EnumError implements CommonEnum{

    BAD_REQUEST("400", "Bad Request!"),
    NOT_AUTHORIZATION("401", "NotAuthorization"),
    NOT_FOUND_REQUEST("404", "Not Found Request Path"),
    METHOD_NOT_ALLOWED("405", "Method Not Allowed"),
    NOT_ACCEPTABLE("406", "Not Acceptable"),
    INTERNAL_SERVER_ERROR("500", "Internal Server Error"),
    LOGIN_FIRST("9998", "[服务器]请登录"),
    RUNTIME_EXCEPTION("9001", "[服务器]运行时异常"),
    NULL_POINTER_EXCEPTION("9002", "[服务器]空值异常"),
    CLASS_CAST_EXCEPTION("9003", "[服务器]数据类型转换异常"),
    IO_EXCEPTION("9004", "[服务器]IO异常"),
    NO_SUCH_METHOD_EXCEPTION("9005", "[服务器]未知方法异常"),
    INDEX_OUT_OF_BOUNDS_EXCEPTION("9006", "[服务器]数组越界异常"),
    CONNECT_EXCEPTION("9007", "[服务器]网络异常"),
    ERROR_VERSION("9008", "[服务器]版本号错误"),
    SQL_Exception("9009", "[服务器]SQL_Exception错误"),
    BAD_SQL_GRAMMAR_EXCEPTION("9010", "[服务器]程序员sql编码错误"),
    ERROR_MEDIA_TYPE("9011", "[服务器]Content-type错误，请使用application/json"),
    EMPTY_REQUEST_BOYD("9012", "[服务器]request请求body不能为空"),
    ERROR_REQUEST_BOYD("9013", "[服务器]request请求body非json对象");



    private final String code;
    private final String msg;

    @Override
    public String getCode() {
        return code;
    }
    @Override
    public String getMsg() {
        return msg;
    }

    EnumError(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getNameByValue(String val) {
        if (val != null) {
            for (EnumError constant : EnumError.values()) {
                if (constant.code.equals(val)) {
                    return constant.msg;
                }
            }
        }
        return "";
    }

    public EnumError getTypeByValue(String value) {
        for (EnumError constant : EnumError.values()) {
            if (constant.code.equals(value)) {
                return constant;
            }
        }
        return null;
    }
}